layui.use(['element','form','layer','table','laydate'],function(){
    $ = layui.jquery
        ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    var layer = layui.layer ,table = layui.table,laydate = layui.laydate,form = layui.form;
    //触发事件
    var active = {
        tabAdd: function(){
            //新增一个Tab项
            element.tabAdd('demo', {
                title: '新选项'+ (Math.random()*1000|0) //用于演示
                ,content: '内容'+ (Math.random()*1000|0)
                ,autoRefresh : true
                ,id: new Date().getTime() //实际使用一般是规定好的id，这里以时间戳模拟下
            })
        }
        ,tabDelete: function(othis){
            //删除指定Tab项
            element.tabDelete('demo', '44'); //删除：“商品管理”

            othis.addClass('layui-btn-disabled');
        }
        ,tabChange: function(){
            //切换到指定Tab项
            element.tabChange('demo', '22'); //切换到：用户管理
        }
    };
    //第一个实例
    let tablreInt3 = '';
    //第一个实例
    tablreInt3 =table.render({
        elem: '#demo3'
        ,id:'tabuser'
        ,height: "auto"
        ,method:"post"
        // ,async : false
        ,url: baseUrl+'withdraw/findAlllist' //数据接口
        ,request: {
            pageName: 'pageNum' //页码的参数名称，默认：page
            ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        ,page: true //开启分页
        ,cols: [[ //表头

            {field: 'userid', title: '用户id',align:'center',sort:true}

            , {field: 'state', title: '审批状态',align:'center',sort:true, templet:function (d) {
                    if(d.state == 1){
                        return "<span style='color: #1E9FFF'>已通过</span>";
                    }else if (d.state == 2) {
                        return "<span style='color: #1E9FFF'>已拒绝</span>";
                    }
                }}
            , {field: 'type', title: '提现类型',align:'center',sort:true, templet:function (d) {
                    if(d.type == 1){
                        return "<span style='color: #1E9FFF'>微信</span>";
                    }else if(d.type == 2){
                        return "<span style='color: #1E9FFF'>支付宝</span>";
                    }else if(d.type == 2){
                        return "<span style='color: #1E9FFF'>银行卡</span>";
                    }
                }}
            , {field: 'name', title: '支付宝名',align:'center',sort:true}
            , {field: 'createTime', title: '申请时间',align:'center',sort:true }
            ,{field: 'account', title: '账户',align:'center',sort:true }
            ,{field: 'money', title: '金额',align:'center',sort:true }
            ,{field: 'openingBank', title: '开户行',align:'center',sort:true}
        ]]
    });

    let tablreInt = '';
        //第一个实例
        tablreInt = table.render({
            elem: '#demo'
            // ,id:'tabuser'
            ,height: "auto"
            ,method:"post"
            ,where : {type:1}
            // ,async : false
            ,url: baseUrl+'withdraw/list' //数据接口
            ,request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,page: true //开启分页
            ,cols: [[ //表头

                {field: 'userid', title: '用户id',align:'center',sort:false}

                , {field: 'state', title: '审批状态',align:'center',sort:false, templet:function (d) {
                        if(d.state == 0){
                            return "<span style='color: #1E9FFF'>审批中</span>";
                        }
                    }}
                , {field: 'type', title: '提现类型',align:'center',sort:false, templet:function (d) {
                        if(d.type == 1){
                            return "<span style='color: #1E9FFF'>微信</span>";
                        }else if(d.type == 2){
                            return "<span style='color: #1E9FFF'>支付宝</span>";
                        }else if(d.type == 2){
                            return "<span style='color: #1E9FFF'>银行卡</span>";
                        }
                    }}
                ,{field: 'createTime', title: '申请时间',align:'center',sort:false }
                ,{field: 'account', title: '账户',align:'center',sort:false }
                ,{field: 'money', title: '金额',align:'center',sort:false }
                ,{fixed: 'right', title: '操作', width:200, align:'center', event:"show", toolbar: '#barDemo2'} //这里的toolbar值是模板元素的选择器
            ]]
        });
        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            if(layEvent == "refuse") { //查看下级
                var uinfo = { "state" : 2,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"withdraw/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ tablreInt.reload(); tablreInt3.reload();index.closed}, 500);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            }else if (layEvent=="agree"){
                var uinfo = { "state" : 1,"id":data.id }
                $.ajax({
                    type: 'post',
                    url: baseUrl+"withdraw/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        //this.location.reload();
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ tablreInt.reload(); tablreInt3.reload();index.closed}, 500);
                        }else{
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            }
        });

    let tablreInt1 = '';
    //第一个实例
    tablreInt1 =table.render({
        elem: '#demo1'
        ,id:'tabuser'
        ,height: "auto"
        ,method:"post"
        // ,async : false
        ,url: baseUrl+'withdraw/list' //数据接口
        ,where : {type:2}
        ,request: {
            pageName: 'pageNum' //页码的参数名称，默认：page
            ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        ,page: true //开启分页
        ,cols: [[ //表头

            {field: 'userid', title: '用户id',align:'center',sort:true}

            , {field: 'state', title: '审批状态',align:'center',sort:true, templet:function (d) {
                    if(d.state == 0){
                        return "<span style='color: #1E9FFF'>审批中</span>";
                    }
                }}
            , {field: 'type', title: '提现类型',align:'center',sort:true, templet:function (d) {
                    if(d.type == 1){
                        return "<span style='color: #1E9FFF'>微信</span>";
                    }else if(d.type == 2){
                        return "<span style='color: #1E9FFF'>支付宝</span>";
                    }else if(d.type == 2){
                        return "<span style='color: #1E9FFF'>银行卡</span>";
                    }
                }}
            , {field: 'name', title: '支付宝名',align:'center',sort:true}
            , {field: 'createTime', title: '申请时间',align:'center',sort:true }
            ,{field: 'account', title: '账户',align:'center',sort:true }
            ,{field: 'money', title: '金额',align:'center',sort:true }
            // ,{fixed: 'right',field: 'userType', title: '操作', width:200, align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
            ,{fixed: 'right', title: '操作', width:200, align:'center', event:"show", toolbar: '#barDemo2'} //这里的toolbar值是模板元素的选择器
        ]]
    });
    //监听工具条
    table.on('tool(test1)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        var tr = obj.tr;
        if(layEvent == "refuse") { //查看下级
            var uinfo = { "state" : 2,"id":data.id }
            //这里一般是发送修改的Ajax请求
            $.ajax({
                type: 'post',
                url: baseUrl+"withdraw/update",
                data: uinfo,
                async:false,
                dataType: 'json',
                success: function(res){
                    //this.location.reload();
                    if(res.meta.code==200){
                        //加载层
                        var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ tablreInt1.reload(); tablreInt3.reload();index.closed}, 500);
                    }else{
                        var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                    }
                }
            });
        }else if (layEvent=="agree"){
            var uinfo = { "state" : 1,"id":data.id }
            $.ajax({
                type: 'post',
                url: baseUrl+"withdraw/update",
                data: uinfo,
                async:false,
                dataType: 'json',
                success: function(res){
                    //this.location.reload();
                    if(res.meta.code==200){
                        var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ tablreInt1.reload(); tablreInt3.reload();index.closed}, 500);
                    }else{
                        var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                    }
                }
            });
        }
    });
    var $ = layui.$, active = {
        reload: function(){
            var demoReload = $('#demoReload');
            //执行重载
            table.reload('tabuser', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    roomName: demoReload.val(),

                }
            });
        }
    };
    let tablreInt2 = '';
    //第一个实例
    tablreInt2 =table.render({
        elem: '#demo2'
        ,id:'tabuser'
        ,height: "auto"
        ,method:"post"
        ,where : {type:3}
        // ,async : false
        ,url: baseUrl+'withdraw/list' //数据接口
        ,request: {
            pageName: 'pageNum' //页码的参数名称，默认：page
            ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        ,page: true //开启分页
        ,cols: [[ //表头

            {field: 'userid', title: '用户id',align:'center',sort:true}

            , {field: 'state', title: '审批状态',align:'center',sort:true, templet:function (d) {
                    if(d.state == 0){
                        return "<span style='color: #1E9FFF'>审批中</span>";
                    }
                }}
            , {field: 'type', title: '提现类型',align:'center',sort:true, templet:function (d) {
                    if(d.type == 1){
                        return "<span style='color: #1E9FFF'>微信</span>";
                    }else if(d.type == 2){
                        return "<span style='color: #1E9FFF'>支付宝</span>";
                    }else if(d.type == 2){
                        return "<span style='color: #1E9FFF'>银行卡</span>";
                    }
                }}
            , {field: 'createTime', title: '申请时间',align:'center',sort:true }
            ,{field: 'account', title: '账户',align:'center',sort:true }
            ,{field: 'money', title: '金额',align:'center',sort:true }
            ,{field: 'openingBank', title: '开户行',align:'center',sort:true}
            // ,{fixed: 'right',field: 'userType', title: '操作', width:200, align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
            ,{fixed: 'right', title: '操作', width:200, align:'center', event:"show", toolbar: '#barDemo2'} //这里的toolbar值是模板元素的选择器
        ]]
    });
    //监听工具条
    table.on('tool(test2)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        var tr = obj.tr;
        if(layEvent == "refuse") { //查看下级
            var uinfo = { "state" : 2,"id":data.id }
            //这里一般是发送修改的Ajax请求
            $.ajax({
                type: 'post',
                url: baseUrl+"withdraw/update",
                data: uinfo,
                async:false,
                dataType: 'json',
                success: function(res){
                    //this.location.reload();
                    if(res.meta.code==200){
                        //加载层
                        var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ tablreInt2.reload(); tablreInt3.reload();index.closed}, 500);
                    }else{
                        var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                    }
                }
            });
        }else if (layEvent=="agree"){
            var uinfo = { "state" : 1,"id":data.id }
            $.ajax({
                type: 'post',
                url: baseUrl+"withdraw/update",
                data: uinfo,
                async:false,
                dataType: 'json',
                success: function(res){
                    //this.location.reload();
                    if(res.meta.code==200){
                        //加载层
                        var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ tablreInt2.reload(); tablreInt3.reload();index.closed}, 500);
                    }else{
                        var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                        setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                    }
                }
            });
        }
    });

    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });



    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

})


